<!--
 * @Author: wangyuan
 * @Date: 2025-04-11 11:03:27
 * @LastEditors: wangyuan
 * @LastEditTime: 2025-04-11 11:12:27
 * @Description: 请填写简介
 * 仅限内部使用
-->
<template>
  <div ref="chartRef" style="width: 600px; height: 400px"></div>
</template>
<script setup>
import { onMounted } from "vue";
import { useEcharts } from "../../hook/ useEcharts";

// 使用自定义 Hook
const { chartRef, initChart, updateChart } = useEcharts();

// 定义 Echarts 配置选项
const option = {
  xAxis: {
    type: "category",
    data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  },
  yAxis: {
    type: "value",
  },
  series: [
    {
      data: [820, 932, 901, 934, 1290, 1330, 1320],
      type: "line",
    },
  ],
};

// 初始化图表
initChart(option);

// 模拟更新图表数据
const updateData = () => {
  const newOption = {
    series: [
      {
        data: [150, 230, 224, 218, 135, 147, 260],
        type: "line",
      },
    ],
  };
  updateChart(newOption);
};

onMounted(() => {
  // 初始化图表
  initChart(option);
});
// 可以在适当的时候调用 updateData 函数来更新图表
</script>
